//
//  ZipTests.m
//  FastTest
//
//  Created by Song Lanlan on 13-9-27.
//  Copyright (c) 2013年 tiantian. All rights reserved.
//

#import "ZipTests.h"

@implementation ZipTests

-(void)estZip{
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];
  
  [self beginAsyncOperation];
  NSString *zipName = @"filter_1977_2";
  
  NSURL *zipURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:zipName ofType:@"zip"]];

  [zipURL jsUnzipToDir:[NSString stringWithFormat:@"%@/filters/",documentsDirectory]
          onCompletion:^(NSDictionary *unzippedFiles) {
            NSLog(@"%@",unzippedFiles);
            
            NSArray *tmp = [zipName componentsSeparatedByString:@"_"];
            NSString* path = unzippedFiles[[NSString stringWithFormat:@"%@.script",tmp[1]]];
            NSString *filterScript = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
            NSLog(@"%@",filterScript);
            
            [self finishedAsyncOperation];
          }];
  
  [self assertAsyncOperationTimeout];
}

-(void)testIterateFiles{
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];

  [JSFileUtils iterateFileInDir:documentsDirectory doWithFile:^(NSString *filePath) {
    if (![filePath isMatchedByRegex:[NSString stringWithFormat:@"%@$",kRegex_FileExtension]]) {
      NSLog(@"%@",filePath);
    }
  }];
}

@end
